
var {getGoodsList,getdetailData} = require('../../api/goods.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
      imgs:[
        "../../image/goods01.jpg",
        "../../image/goods02.jpg",
        "../../image/goods03.jpg",
        "../../image/goods04.jpg"
      ],
      iconArray:[
        {
          url:"../../image/icon-qiandao.png",
          text:"签到"
        },
        {
          url:"../../image/icon-fujin.png",
          text:"附近"
        },
        {
          url:"../../image/icon-zhanhui.png",
          text:"展会"
        },
        {
          url:"../../image/icon-fuli.png",
          text:"福利"
        },
        {
          url:"../../image/icon-muma.png",
          text:"玩乐"
        },
        {
          url:"../../image/icon-tiyu.png",
          text:"体育"
        },
        {
          url:"../../image/icon-xingxing.png",
          text:"周边"
        },
        {
          url:"../../image/icon-qinzi.png",
          text:"亲子"
        }
      ],
      goodsList:[
        {
          id:"1",
          goodsImage:"../../image/goods01.jpg",
          goodsName:"1商品名称商品名称商品名称",
          goodsAddress:"广州",
          goodsPrice:"200"
        },
        {
          id:"1",
          goodsImage:"../../image/goods01.jpg",
          goodsName:"2商品名称商品名称商品名称",
          goodsAddress:"广州",
          goodsPrice:"200"
        },
        {
          id:"1",
          goodsImage:"../../image/goods01.jpg",
          goodsName:"3商品名称商品名称商品名称",
          goodsAddress:"广州",
          goodsPrice:"200"
        },
      ]
  },

  // 自定义方法
  navtab(){
    console.log("点击事件");
    // 跳转页面 navtab 导航栏
    wx.switchTab({
      url: '/pages/category/category',
    })
    // 跳转除navtab 导航栏外其他页面 ，打开新窗口
    // wx.navigateTo({
    //   url: '/pages/details/details',
    // })
  },  


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(getGoodsList);

    // getGoodsList().then((data)=>{
    //   console.log("获取数据----》》》》",data);
    // })

    // getdetailData({goods_id:57444}).then(data=>{
    //   console.log("获取数据详情页----》》》》",data);
    // })


    // getGoodsList(function(res){
    //   console.log("获取数据----》》》》",res);
    // })

    // getdetailData({goods_id:57444},function(res){
    //   console.log("获取数据详情页----》》》》",res);
    // })



      this.getGoodsData();
    

  },
  // 请求数据
  getGoodsData(){
    // 请求数据
    let _this = this;
    wx.request({
      url: 'https://api-hmugo-web.itheima.net/api/public/v1/goods/search', //仅为示例，并非真实的接口地址
      header: {
        'content-type': 'application/json' // 默认值
      },
      success (res) {
        console.log(res.data.message.goods)
        let goodslist = res.data.message.goods;
        let lists = [];
        goodslist.forEach(item=>{
          let {goods_id,goods_name,goods_small_logo,goods_price} = item;
          let data = {
              id:goods_id,
              goodsImage:goods_small_logo,
              goodsName:goods_name,
              goodsAddress:"广州",
              goodsPrice:goods_price
            }
          if(goods_small_logo){
            lists.push(data);
          }
        })

        // 修改数据
        _this.setData({
          goodsList:lists
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})